import numpy as np
from sklearn.datasets import load_iris
# 部分鸢尾花数据集
iris_dataset = load_iris().data[:30]
def bootstrap(dataset: np.ndarray):
    """
    自己实现自助法采样
    :return:train_set,test_set
    """
    rows = iris_dataset.shape[0]
    # 产生可重复采样随机索引
    rand_idx = np.random.randint(rows, size=(rows,))
    # 索引去重
    unique_rand_idx = np.setdiff1d(np.arange(dataset.shape[0]), rand_idx)
    return dataset[rand_idx], dataset[unique_rand_idx]
train_set, test_set = bootstrap(iris_dataset)
print("训练集大小:{}\n训练集:\n{}\n测试集大小:{}\n测试集:\n{}".format(train_set.shape, train_set,
                                                test_set.shape,test_set))
